<?php

namespace app\admin\model;

use think\Model;


class Job extends Model
{

    

    

    // 表名
    protected $name = 'job';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'job_is_group_text',
        'job_type_text',
        'status_text'
    ];
    

    
    public function getJobIsGroupList()
    {
        return ['0' => __('Job_is_group 0'), '1' => __('Job_is_group 1')];
    }

    public function getJobTypeList()
    {
        return ['1' => __('Job_type 1'), '2' => __('Job_type 2'), '3' => __('Job_type 3'), '4' => __('Job_type 4')];
    }

    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'),'4' => __('Status 4'),'5' => __('Status 5')];
    }


    public function getJobIsGroupTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['job_is_group']) ? $data['job_is_group'] : '');
        $list = $this->getJobIsGroupList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getJobTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['job_type']) ? $data['job_type'] : '');
        $list = $this->getJobTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function hotel()
    {
        return $this->belongsTo('Hotel', 'hotel_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function company()
    {
        return $this->belongsTo('Company', 'job_company_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function usergroup()
    {
        return $this->belongsTo('Company', 'job_company_group_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function area()
    {
        return $this->belongsTo('app\admin\model\Area', 'city_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
